
<!DOCTYPE html>
<html>
<head>
    <title>地址管理</title>
    {include file="public/head" /}
    <div class="mfc cbox headtop fl">
        <div class="sreach ret mfc ">
            <span class="fa fa-angle-left pabs-l-box fa-2x tc" style="width:1.6em;" onclick="history.go(-1)"></span>
            <p class="tc" onclick="history.go(-1)" style="font-size: 18px;">返回</p>
            <!--        <span class="pabs-r-box c-red tc" style="padding: 0 0.6em;"> 保存 </span>-->
        </div>
    </div>
<body class="bc-white">
<div class="mfc adress bc-back fl ">
    <div class="cbox gap">
        <div class="adress-add bsilk  lh30">
            <span class="fa icon-site-add fs12 "> <a href="{:url('create')}">增加新收货地址</a> </span>
        </div>
        <div class="adress-list fs12">

        </div>
        <div class="mfc fl">
<!--            <div class="adress-default">-->
<!--                <span>设置为默认地址</span><input class="fr" type="checkbox" name="isDefault">-->
<!--            </div>-->
            <div class="mfc tci asss" id="asss">
                <button class="btnbox oval fs12">默认地址确认</button>
            </div>
        </div>
    </div>
</div>


<div class="mfc  pfix-b-box hidden">
    <div class="cbox order-option tci card">
        <button class="btnbox oval">默认地址确认</button>
    </div>
</div>

</body>
</html>
<script>
    $('.btnbox').click(function () {
        var checked = false;//选中状态
        $('[name=adress]').each(function (k, v) {

            if ($(this).is(':checked')) {
               var id = $(this).val();
                checked = true;
                $.ajax({
                    type: "POST", //用POST方式传输
                    dataType: "json", //数据格式:JSON
                    url: "{:url('set_default')}", //目标地址
                    data:{id:id},
                    async: false,
                    success: function (ret) {
                        if(ret.code == 200){ //注册成功
                            layer.msg(ret.message);
                            setTimeout(function () {
                                history.go();
                            },1000)
                        }else{
                            layer.msg(ret.message);
                            return false;
                        }
                    }
                });
            }

        });
        if(checked == false){
            layer.msg('没有选中状态');
        }
    });
    $.ajax({
        type: "POST", //用POST方式传输
        dataType: "json", //数据格式:JSON
        url: "{:url('index')}", //目标地址
        async: false,
        success: function (ret) {
            if(ret.code == 200){ //注册成功
                var str = '';

                if(ret.data.length ==0){

                    $('.asss').hide();
                }
                $.each(ret.data,function(k,v){

                    if(v.status == 2){
                        var che = 'checked';
                    var checked =  '<span class="default">默认</span>';
                    }else{
                    var checked =  '';
                        var che =  '';
                    }
                    if(k == 0){

                    }else{

                    }
                    str += '<div class="mfc fl">\n' +
                        '                <div class="cell">\n' +
                       '<input type="radio" '+che+' name="adress" value="'+v.id+'">' +
                        '                    <div class="info">\n' +
                        '                        <p onclick="back('+v.id+')"><span>'+v.name+'</span> <span class="">'+v.mobile+'</span> '+checked+'</p>\n' +
                        '                        <p onclick="back('+v.id+')" class="imark">'+v.prov+' '+v.city+' '+v.area+' '+v.address+'</p>\n' +
                        '                    </div>\n' +
                        '                    <span class="pabs-r-box fa fa-pencil-square-o c-gray" onclick="update_view('+v.id+')" ></span>\n' +
                        '                </div>\n' +
                        '            </div>';
                });
                $('.adress-list').html(str);

            }else{
                layer.msg(data.message);
                return false;
            }
        }
    });

    function update_view(id) {
        window.location.href = "{:url('update')}?id=" + id;
    }

    function back(id) {
        var url = localStorage.getItem('gift_address');
        var index = "{:input('from')}";
        if (!index) {
            window.location.href = url + '&address_id=' + id;
        }

    }

</script>